package com.example.kafka.consumer;

import com.example.kafka.holder.SetMethodHolder;
import com.example.kafka.pojo.IndicatorData;

import java.util.HashMap;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.function.Supplier;

public class Biconumer {

    public static void main(String[] args) {
        IndicatorData apple = new IndicatorData();
//        // 苹果加工成水果沙拉
//        IndicatorData fruitSalad = madeFruitSalad(apple, IndicatorData::getComponent, IndicatorData::setComponent, IndicatorData::new);
//        System.out.println("打印fruitSalad-----------" + fruitSalad + "---------");
        Map<String,SetMethodHolder<IndicatorData, String>> map = new HashMap<>();
        map.put("",new SetMethodHolder<>(IndicatorData::setComponent,String.class));

        map.get("").getSet().accept(apple,"");
     }

    private static <T> T madeFruitSalad(T apple, Function<T, String> getName,
                                        BiConsumer<T, String> setName, Supplier<T> supplier) {
        // 调用get方法
        System.out.println("调用get方法--------------" + getName.apply(apple) + "--------");
        // 实例化一个空模型
        T model = supplier.get();
        // 调用set方法
        setName.accept(model, getName.apply(apple) + "沙拉");
        return model;
    }

}
